<?php

require_once(PATH_CLASS.'widget.class.php');
require_once(PATH_CLASS.'match.class.php');

class comingEvents extends widget{
  
  const CLASS_NAME = "comingEvents";
  
  public function getDefaults() {
    $ret = parent::getDefaults();
    //getComingDatesLayout($saison_id=null,$type=null,$limit=3,$pars=array()){
    $ret = array_merge(array(
       'saison_id'  => null
      ,'type'       => null
      ,'limit'      => 3
      ,'pars'       => array()
    ),$ret);
    
    return $ret;
  }

  protected function _get_called_class() { return self::CLASS_NAME;  }
  
  public function _render() {
    $pars = $this->params;
    if($pars['limit']==0 || is_nan($pars['limit'])){
      $pars['limit'] = 3;
    }

    $p = array_merge($pars['pars'],array('limit'=>$pars['limit']));

    $cal = match::getComingDates($pars['saison_id'], $pars['type'], $p);

    if(is_array($cal->matchs) && count($cal->matchs)>0){

      $params = array(
           'matchs'   => $cal->matchs
          ,'lieux'    => $cal->lieux
          ,'compets'  => $cal->compets
      );

      $params = array_merge($params,$pars);

      $layout = self::renderTplFromFile(__FILE__, $params);
      
      return $layout;

    }
    
    
//    $ret = match::getComingDatesLayout(null,null,3);
    
    //$ret = $this->_render();
    
    return "";    
    
    
  }
}

